home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / skipandgouls.swf / scripts / __Packages / HUD.as < prev    next >
Text File  |  2007-10-01  |  8KB  |  288 lines

  1. class HUD
  2. {
  3.    static var DEFAULT_LIFE = 3;
  4.    static var SCORE_INCREASE_RATE = 100;
  5.    static var CANDY_APPEAR_CHANCE = 0.07;
  6.    function HUD(l_mc)
  7.    {
  8.       this.mc = l_mc;
  9.       this.setItem();
  10.       if(!HUD.nLife)
  11.       {
  12.          this.resetLife();
  13.       }
  14.       this.nMinutes = 0;
  15.       this.nSeconds = 0;
  16.       this.bTimerTick = false;
  17.       this.initTimerInterval();
  18.       this.initCandy();
  19.       this.nScore = 0;
  20.       this.oLifeField = new sarbakan.packaging.DigitBitmapField([this.mc.mcLife0,this.mc.mcLife1]);
  21.       this.oTimeMinField = new sarbakan.packaging.DigitBitmapField([this.mc.mcTime0,this.mc.mcTime1]);
  22.       this.oTimeSecField = new sarbakan.packaging.DigitBitmapField([this.mc.mcTime2,this.mc.mcTime3]);
  23.       this.oScoreField = new sarbakan.packaging.DigitBitmapField([this.mc.mcPoint0,this.mc.mcPoint1,this.mc.mcPoint2,this.mc.mcPoint3,this.mc.mcPoint4,this.mc.mcPoint5]);
  24.       this.oScoreField.setContent(0);
  25.       this.onOptionClosed();
  26.    }
  27.    function update()
  28.    {
  29.       if(!_global.C.bRestartGame && !_global.C.bRestarting)
  30.       {
  31.          this.oLifeField.setContent(HUD.nLife);
  32.       }
  33.       this.updateTime();
  34.       this.updateScore();
  35.       this.updateMenu();
  36.    }
  37.    function resetLife()
  38.    {
  39.       HUD.nLife = HUD.DEFAULT_LIFE;
  40.    }
  41.    function setItem(l_nItemID)
  42.    {
  43.       switch(l_nItemID)
  44.       {
  45.          case maze.MazeData.ELEMENT_PUMPKIN:
  46.             this.mc.mcItem.gotoAndStop("pumpkin");
  47.             break;
  48.          case maze.MazeData.ELEMENT_SLUG:
  49.             this.mc.mcItem.gotoAndStop("slug");
  50.             break;
  51.          default:
  52.             this.mc.mcItem.gotoAndStop("empty");
  53.       }
  54.       this.nCurrentItemID = l_nItemID;
  55.    }
  56.    function setScore(l_nScore)
  57.    {
  58.       this.nScore = l_nScore;
  59.       this.oScoreField.setContent(this.nScore);
  60.    }
  61.    function setTimer(l_nMinutes, l_nSeconds)
  62.    {
  63.       this.nMinutes = l_nMinutes;
  64.       this.nSeconds = l_nSeconds;
  65.    }
  66.    function getItem()
  67.    {
  68.       return this.nCurrentItemID;
  69.    }
  70.    function useItem()
  71.    {
  72.       this.setItem();
  73.    }
  74.    function gainLife()
  75.    {
  76.       HUD.nLife = HUD.nLife + 1;
  77.    }
  78.    function loseLife()
  79.    {
  80.       if(--HUD.nLife == 0)
  81.       {
  82.          _global.C.endGame(false);
  83.          this.resetLife();
  84.       }
  85.       else
  86.       {
  87.          _global.C.restartGame();
  88.       }
  89.       delete this.mc.mcCandy.onRelease;
  90.    }
  91.    function increaseScore(l_nAmount)
  92.    {
  93.       this.nScore += l_nAmount;
  94.    }
  95.    function showGetOut()
  96.    {
  97.       if(!_global.C.bSamePart)
  98.       {
  99.          sarbakan.sound.SoundManager.play("start" + _global.C.nLevelPart,maze.MazeData.VOLUME_DUTCHSTART,1);
  100.       }
  101.       this.mc.mcGetOut.gotoAndPlay(1);
  102.       this.mc.mcGetOut.text.gotoAndStop("level");
  103.    }
  104.    function onGetOutEnd()
  105.    {
  106.       _global.C.oSpongeBob.setState("idle");
  107.       if(_global.C.nLevelPart < 4)
  108.       {
  109.          _global.C.oWater.setState("idle");
  110.       }
  111.    }
  112.    function onTimerTick()
  113.    {
  114.       this.bTimerTick = true;
  115.    }
  116.    function onOptionOpened()
  117.    {
  118.       this.bMenuOpening = false;
  119.       this.mc.mcOptions.stop();
  120.       this.initOptionsMenu();
  121.    }
  122.    function onOptionClosed()
  123.    {
  124.       this.bMenuOpened = false;
  125.       this.bMenuOpening = false;
  126.       this.mc.mcOptions.gotoAndStop("idle");
  127.       this.initOptionsButton();
  128.       this.initTimerInterval();
  129.    }
  130.    function onButtonOptions()
  131.    {
  132.       _global.C.togglePause();
  133.       this.mc.mcOptions.gotoAndPlay("opens");
  134.       this.bMenuOpened = true;
  135.       this.bMenuOpening = true;
  136.       this.bCandyShown = false;
  137.       this.mc.mcCandy._visible = false;
  138.       this.clearTimerInterval();
  139.    }
  140.    function onButtonInstructions()
  141.    {
  142.       _global.C.oPackaging.goto("instructions",true);
  143.    }
  144.    function onButtonQuit()
  145.    {
  146.       this.mc.mcOptions.mcQuit.gotoAndStop("menu");
  147.       this.mc.mcOptions.mcQuit.btYes.onRelease = sarbakan.utils.Delegate.create(this,this.onButtonQuitYes);
  148.       this.mc.mcOptions.mcQuit.btNo.onRelease = sarbakan.utils.Delegate.create(this,this.onButtonQuitNo);
  149.    }
  150.    function onButtonQuitYes()
  151.    {
  152.       _global.C.endGame(false);
  153.       HUD.nLife = HUD.DEFAULT_LIFE;
  154.    }
  155.    function onButtonQuitNo()
  156.    {
  157.       this.mc.mcOptions.mcQuit.gotoAndStop("inactive");
  158.       this.onButtonClose();
  159.    }
  160.    function onButtonClose()
  161.    {
  162.       _global.C.togglePause();
  163.       this.mc.mcOptions.gotoAndPlay("closes");
  164.    }
  165.    function onButtonMusic()
  166.    {
  167.       if(sarbakan.sound.SoundManager.isMuted())
  168.       {
  169.          sarbakan.sound.SoundManager.unmute();
  170.       }
  171.       else
  172.       {
  173.          sarbakan.sound.SoundManager.mute();
  174.       }
  175.       this.initOptionsMenu();
  176.    }
  177.    function onCandyClick()
  178.    {
  179.       if(!sarbakan.visual.PauseManager.bPaused)
  180.       {
  181.          _global.C.togglePause();
  182.          this.bCandyShown = false;
  183.          this.mc.mcCandy._visible = false;
  184.          this.mc.mcEasterEgg.gotoAndPlay(2);
  185.          sarbakan.sound.SoundManager.play("vampire",maze.MazeData.VOLUME_EASTEREGG,1);
  186.          sarbakan.sound.SoundManager.play("thunder",maze.MazeData.VOLUME_THUNDER,1);
  187.       }
  188.    }
  189.    function onEasterEggEnd()
  190.    {
  191.       _global.C.togglePause();
  192.       this.mc.mcEasterEgg.gotoAndStop(2);
  193.    }
  194.    function updateTime()
  195.    {
  196.       if(this.bTimerTick && !sarbakan.visual.PauseManager.bPaused)
  197.       {
  198.          if(++this.nSeconds == 60)
  199.          {
  200.             this.nSeconds = 0;
  201.             this.nMinutes = this.nMinutes + 1;
  202.          }
  203.          this.updateCandy();
  204.          this.bTimerTick = false;
  205.       }
  206.       this.oTimeMinField.setContent(this.nMinutes);
  207.       this.oTimeSecField.setContent(this.nSeconds);
  208.    }
  209.    function updateScore()
  210.    {
  211.       var _loc2_ = this.oScoreField.getContent();
  212.       if(_loc2_ < this.nScore)
  213.       {
  214.          _loc2_ += HUD.SCORE_INCREASE_RATE;
  215.          if(_loc2_ > this.nScore)
  216.          {
  217.             _loc2_ = this.nScore;
  218.          }
  219.          this.oScoreField.setContent(_loc2_);
  220.       }
  221.    }
  222.    function initCandy()
  223.    {
  224.       this.bCandyShown = false;
  225.       this.mc.mcCandy.onRelease = sarbakan.utils.Delegate.create(this,this.onCandyClick);
  226.    }
  227.    function updateCandy()
  228.    {
  229.       if(!this.bCandyShown && Math.random() < HUD.CANDY_APPEAR_CHANCE)
  230.       {
  231.          this.bCandyShown = true;
  232.          this.mc.mcCandy._visible = true;
  233.          this.mc.mcCandy._x = sarbakan.utils.MoreMath.random(5,560);
  234.          this.bCandyShownCount = 0;
  235.       }
  236.       else if(++this.bCandyShownCount == 2)
  237.       {
  238.          this.bCandyShown = false;
  239.          this.mc.mcCandy._visible = false;
  240.       }
  241.    }
  242.    function updateMenu()
  243.    {
  244.       if(_global.C.oSpongeBob.oKey.P && !this.bMenuOpening)
  245.       {
  246.          if(!this.bMenuOpened)
  247.          {
  248.             this.onButtonOptions();
  249.          }
  250.          else
  251.          {
  252.             this.onButtonClose();
  253.          }
  254.       }
  255.    }
  256.    function initOptionsButton()
  257.    {
  258.       this.mc.mcOptions.btOptions.onRelease = sarbakan.utils.Delegate.create(this,this.onButtonOptions);
  259.    }
  260.    function initOptionsMenu()
  261.    {
  262.       this.mc.mcOptions.mcMenu.btClose.onRelease = sarbakan.utils.Delegate.create(this,this.onButtonClose);
  263.       this.mc.mcOptions.mcMenu.btInstructions.onRelease = sarbakan.utils.Delegate.create(this,this.onButtonInstructions);
  264.       this.mc.mcOptions.mcMenu.btQuit.onRelease = sarbakan.utils.Delegate.create(this,this.onButtonQuit);
  265.       this.mc.mcOptions.mcMenu.btMusicOn.onRelease = sarbakan.utils.Delegate.create(this,this.onButtonMusic);
  266.       this.mc.mcOptions.mcMenu.btMusicOff.onRelease = sarbakan.utils.Delegate.create(this,this.onButtonMusic);
  267.       if(sarbakan.sound.SoundManager.isMuted())
  268.       {
  269.          this.mc.mcOptions.mcMenu.btMusicOn._visible = false;
  270.          this.mc.mcOptions.mcMenu.btMusicOff._visible = true;
  271.       }
  272.       else
  273.       {
  274.          this.mc.mcOptions.mcMenu.btMusicOn._visible = true;
  275.          this.mc.mcOptions.mcMenu.btMusicOff._visible = false;
  276.       }
  277.    }
  278.    function initTimerInterval()
  279.    {
  280.       this.clearTimerInterval();
  281.       this.nTimerInterval = setInterval(sarbakan.utils.Delegate.create(this,this.onTimerTick),1000);
  282.    }
  283.    function clearTimerInterval()
  284.    {
  285.       clearInterval(this.nTimerInterval);
  286.    }
  287. }
  288.